import React, { Component } from "react";

import { PickerView } from "antd-mobile";

import FilterFooter from "../../../../components/FilterFooter";

export default class FilterPicker extends Component {
  state = {
    // 存储当前筛选条件下 所选中的值
    // value: null,
    value: this.props.defaultSelected
  };
  // constructor(props) {
  //   super(props);
  //   console.log('FilterPicker组件创建了');
  //   this.state = {
  //     value: this.props.defaultSelected
  //   }
  // }

  render() {
    // 接收父组件传递过来的函数 并解构为变量 方便调用
    const { onCancel ,onSave ,data ,col ,type } = this.props;
    const { value } = this.state
    return (
      <>
        {/* 选择器组件： */}
        <PickerView
          data={data}
          value={value}
          cols={col}
          onChange={(val) => {
            this.setState({
              value: val,
            });
          }}
        />

        {/* 底部按钮 */}
        {/* 通过 onSave 函数的参数把获取到的值传递给父组件 */}
        <FilterFooter onCancel={() => onCancel(type)} onOk={() => onSave( type, value )} />
      </>
    );
  }
}
